﻿namespace JNPF.Utils
{
    /// <summary>
    /// RedisCacheExpire
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// </summary>
    public static class RedisCacheExpire
    {
        public static void Run()
        {
            var db = RedisConnection.Connection.GetDatabase();
            var subscriber = RedisConnection.Connection.GetSubscriber();
            var notificationChannel = "__keyevent@0__:expired";
            subscriber.Subscribe(notificationChannel, (channel, notificationType) =>
            {
                var key = GetKey(channel);
                //switch (notificationType)
                //{
                //    case "expire":
                //        Console.WriteLine("Expiration Set for Key: " + key);
                //        break;
                //    case "expired":
                //        Console.WriteLine("Expiration hit for Key: " + key);
                //        break;
                //}
            });
        }
        private static string GetKey(string channel)
        {
            var index = channel.IndexOf(':');
            if (index >= 0 && index < channel.Length - 1)
                return channel.Substring(index + 1);
            return channel;
        }
    }
}
